package com.ktwlsoft.archivemanage.controller;

import com.ktwlsoft.archivemanage.domain.business.businessService.SysConfigService;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.sysConfig.SysConfigUpdateRequest;
import com.ktwlsoft.archivemanage.service.security.UserAuthenticate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author JokerMo
 * @version 1.0
 * @date 2020/3/12 16:31
 */
@Api(value = "数据权限", description = "数据权限")
@RestController
@RequestMapping("/sysConfig")
public class SysConfigController {
    //引入service
    private final SysConfigService sysConfigService;

    public SysConfigController(SysConfigService sysConfigService) {
        this.sysConfigService = sysConfigService;
    }

    @ApiOperation(value = "编辑数据权限", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("/updateSysConfig")
    @UserAuthenticate(actionCode = "BUSINESS_GUIDANCE_B_POWER")
    public ResponseEntity<?> updateSysConfig(@Valid @RequestBody SysConfigUpdateRequest request) {
        sysConfigService.update(request);
        return ResponseEntity.ok(Result.ok("操作完成"));
    }

    @ApiOperation(value = "获取数据权限配置", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("/getSysConfig")
    public ResponseEntity<?> getSysConfig() {
        return ResponseEntity.ok(sysConfigService.getSysConfig());
    }

    @ApiOperation(value = "app检测更新", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("/appUpdate")
    public ResponseEntity<?> appUpdate(@RequestParam Integer versionNum) {
        return ResponseEntity.ok(sysConfigService.appUpdate(versionNum));
    }
}
